package com.thinkverse.search.controller;

import com.thinkverse.common.result.Result;
import com.thinkverse.search.service.SearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 检索控制器
 */
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchController {
    
    private final SearchService searchService;
    
    /**
     * 全文检索
     */
    @GetMapping("/fulltext")
    public Result<List<Map<String, Object>>> fullTextSearch(@RequestParam String keyword,
                                                          @RequestParam(defaultValue = "0") Integer page,
                                                          @RequestParam(defaultValue = "10") Integer size) {
        List<Map<String, Object>> results = searchService.fullTextSearch(keyword, page, size);
        return Result.success(results);
    }
    
    /**
     * 高级检索
     */
    @PostMapping("/advanced")
    public Result<List<Map<String, Object>>> advancedSearch(@RequestBody Map<String, Object> searchParams) {
        List<Map<String, Object>> results = searchService.advancedSearch(searchParams);
        return Result.success(results);
    }
    
    /**
     * 分级检索
     */
    @GetMapping("/hierarchical")
    public Result<List<Map<String, Object>>> hierarchicalSearch(@RequestParam String keyword,
                                                               @RequestParam String userRole,
                                                               @RequestParam(defaultValue = "0") Integer page,
                                                               @RequestParam(defaultValue = "10") Integer size) {
        List<Map<String, Object>> results = searchService.hierarchicalSearch(keyword, userRole, page, size);
        return Result.success(results);
    }
    
    /**
     * 获取搜索建议
     */
    @GetMapping("/suggest")
    public Result<List<String>> getSearchSuggestions(@RequestParam String keyword) {
        List<String> suggestions = searchService.getSearchSuggestions(keyword);
        return Result.success(suggestions);
    }
}
